﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SystemContainer.Models;
using System.Data.Entity;

namespace SystemContainer.Controllers
{
    
    public class DataProcessController : Controller
    {
        public AlgoAndData activeObject = new AlgoAndData();
        private SystemEntities systemDB = new SystemEntities();
        /*SystemEntities systemDB = new SystemEntities
        {
            Fields=new List <Field>
            {   new Field{Name="Mobile",FieldID=1,  Algorithms=new List<Algorithm>
            {
                new Algorithm{ Name="f1Algo1",AlgorithmID=1,FieldID=1},
                new Algorithm{ Name="f1Algo2",AlgorithmID=2,FieldID=1},
                new Algorithm{ Name="f1Algo3",AlgorithmID=3,FieldID=1},
                new Algorithm{ Name="f1Algo4",AlgorithmID=4,FieldID=1}

            }},
                new Field{Name="Video",FieldID=2,  Algorithms=new List<Algorithm>
            {
                new Algorithm{ Name="f2Algo1",AlgorithmID=1,FieldID=2},
                new Algorithm{ Name="f2Algo2",AlgorithmID=2,FieldID=2},
                new Algorithm{ Name="f2Algo3",AlgorithmID=3,FieldID=2},
                new Algorithm{ Name="f2Algo4",AlgorithmID=4,FieldID=2}

            }},
                new Field{Name="Geotag",FieldID=3,  Algorithms=new List<Algorithm>
            {
                new Algorithm{ Name="f3Algo1",AlgorithmID=1,FieldID=3},
                new Algorithm{ Name="f3Algo2",AlgorithmID=2,FieldID=3},
                new Algorithm{ Name="f3Algo3",AlgorithmID=3,FieldID=3},
                new Algorithm{ Name="f3Algo4",AlgorithmID=4,FieldID=3}

            }}
            },
            Algorithms=new List<Algorithm>
            {
                new Algorithm{ Name="Algo1",AlgorithmID=1,FieldID=1},
                new Algorithm{ Name="Algo2",AlgorithmID=2,FieldID=1},
                new Algorithm{ Name="Algo3",AlgorithmID=3,FieldID=3},
                new Algorithm{ Name="Algo4",AlgorithmID=4,FieldID=2}

            },
            DataSets=new List<DataSet>
            {
                new DataSet{Name="DataSet1",DataSetID=1},
                new DataSet{Name="DataSet2",DataSetID=2},
                new DataSet{Name="DataSet3",DataSetID=3},
                new DataSet{Name="DataSet4",DataSetID=4}
            }
         };*/
        //
        // GET: /DataProcess/
    

        public ActionResult BrowseField()

        {
            var fields = systemDB.Fields.ToList();
            return View(fields);
        }

        public Field BrowseAlgorithm(string fieldName)
        {
            Field fieldModel = systemDB.Fields.Include("Algorithms").Single(f=>f.Name==fieldName );
            return fieldModel;
        }
        public List<DataSet> BrowseDataSet(int algorithmID)
        {   
            AlgoAndData.AlgorithmID = algorithmID;
            ViewBag.AlgorithmName = systemDB.Algorithms.Find(algorithmID).Name;
            ViewBag.AlgorithmID = algorithmID;
            List<DataSet> dataList = (List<DataSet>)systemDB.Algorithms.Include("datas").Single(a => a.AlgorithmID == algorithmID).datas;
            return dataList;

        }
        public ActionResult BrowseLocation(string locationName)
        {
            Console.Write(locationName);
            Location locationCenter = systemDB.Cities.Single(l => l.locationName == locationName);
            return Json(locationCenter);
        }
        public string PostDataSet(String dataSetName)
        {
            //AlgoAndData.DataSetID = systemDB.PhotoData.Single(a=>a.Name==dataSetName).DataSetID;
            return dataSetName;
        }
  

    }
}
